<?php
	defined('_JEXEC') or die('Restricted access');
	require_once(CUTEENGINE_BASE_ACTION_PATH."base_action_class.php");
    require_once(CUTEENGINE_BASE_STEP_PATH."base_step_class.php");
	require_once(CUTEENGINE_FIELDS_PATH."field_grid".DIRECTORY_SEPARATOR."field_grid.php");
	//
    // t_action_set_values_into_db
    //
	class t_action_set_values_into_db extends t_base_action
	{
        // property declaration
		// protected        
		const language_position_ok_message = 1;
		const language_position_error_message = 2;
		const language_position_invalid_fields_values = 3;
		const language_position_last = 4;
		
		// P
        protected $page_fields = array();

		// property declaration
		// public
		// P
        const proper_properties_position_per_SQL = 0;
        const proper_properties_position_per_page_fields = 1;
        const proper_properties_position_per_fixed_fields_names = 2;
        const proper_properties_position_per_fixed_fields_values = 3;
        const proper_properties_position_per_use_custom_language = 4;
        const proper_properties_position_last = 5;
        // R
        const required_fields_count = 4;
      
        // method declaration
		// prviate
		//R
		private function import_page_fields_from_paret_part()
		{
			$this->page_fields = json_decode($this->parent_part->get_json_db_fields_list());	
		}
    	// protected
        // G
		static function get_help_proper_property($a_index)
		{
			$local_return = 'NO HELP AVAILABLE';
			/*switch ($a_index) 
            {
                case self::proper_properties_position_:
					$local_return = '';
				break;                
			}*/
			return $local_return;
		}
        static function get_default_proper_property($a_index)
		{
			$local_return = '';
			//echo "a_index: $a_index<br>";
			/*switch ($a_index) 
            {
				case self::proper_properties_position_per_:
					$local_return = '';
				break;				
			}*/
			return $local_return;
		}		
        protected function get_proper_properties_position_last()
        {
            return self::proper_properties_position_last;
        }
		protected function get_required_fields_count()
        {
            return self::required_fields_count;
        }
        

		// I
        protected function initialize_action()
        {		

			//echo "initialize_action<br>";
			if (! $this->initialized)
			{
                parent::initialize_action();
				
				//var_dump($this->proper_properties_array[self::proper_properties_position_per_page_fields]); 
				// page_fields
				$this->page_fields = $this->proper_properties_array[self::proper_properties_position_per_page_fields];
                //$this->initialized = true;

			}
			return $this->initialized;
		}		
        protected function initialize_step_execution()
        {		
			//echo "this->current_step_index: $this->current_step_index<br>";
			$local_step = $this->steps_list[$this->current_step_index];
			$local_index = $this->current_step_index;
			$local_step->initialize();
			$local_class = get_class($local_step);
			
			if (($local_index == t_base_action::step_criteria) || ($local_index == t_base_action::step_result)) 
			{
				$this->custom_execute_step($local_step);                        
			}    
			else
			{
				$this->execute_step($local_step);                                            
			}
		}	
        protected function custom_execute_step($a_step)        
        {
            //echo __METHOD__."this->current_step_index: $this->current_step_index<br>";
            $local_next_step = $this->steps_list[$this->current_step_index + 1];
			$local_field = $a_step->field;
			if ($local_field)
			{
				$local_start_tag = $local_field->get_start_tag();
				$local_field_class = get_class($local_field);    
			}			
		    $local_class = get_class($a_step);
           
            switch ($local_class) 
            {
				/*********** t_step_ajax_get ***********/
				case t_step_ajax_get:
                    if (($local_field_class === t_field_grid) || (! $local_field))
                    {
                        $a_step->code .="
    ".$this->get_content_loader_code($local_next_step->code);
                    }
					else if ($local_field_class === t_field_form) 
                    {
						$a_step->code = "
		var local_parent = ".t_cuteengine::javascript_instance_name."['".$local_start_tag->name."'];
		var local_argoument = local_parent.prepare_childs_values_to_send('".$local_start_tag->name."');
        if (!local_argoument)
            return false;
		". $this->get_content_loader_code($local_next_step->code,true,true);
					}
                    else
                    {
                        $a_step->code = "
    var local_target = event.target ? event.target : event.srcElement;
    var local_argoument = this.html_tag('".$local_start_tag->name."').keys";
                        
                        foreach ($this->page_fields as $local_field_index => $local_field) 
                        {
                            if ($local_field_index == 0)  
                                $a_step->code .= '+ "'.t_url_parameter::separator_level_0."\" + hide_separator(this.html_tag(\"".$this->page_fields[$local_field_index]."\").value) ";
                            else    
                                $a_step->code .= '+ "'.t_url_parameter::separator_level_1."\" + hide_separator(this.html_tag(\"".$this->page_fields[$local_field_index]."\").value) ";
                        }	
                        $a_step->code .= ";
    ". $this->get_content_loader_code($local_next_step->code);
					}
                break;                

					
                /*********** t_step_ajax_put ***********/
                case t_step_ajax_put:

                break;                
            }
        }
        protected function load_language()
		{
            //echo __METHOD__;
            global $g_ambient_namespace;
           // echo 'this->proper_properties_array[self::proper_properties_position_per_use_custom_language]: '.$this->proper_properties_array[self::proper_properties_position_per_use_custom_language]."<br>";
            if (strtoupper($this->proper_properties_array[self::proper_properties_position_per_use_custom_language]) == 'TRUE')
                $g_ambient_namespace->load_custom_language($this,$this->get_action_name());
            else    
                $g_ambient_namespace->load_language($this);
        }
        // method declaration
    	// public
        public function __construct($a_parent_component,$a_parent_part,$a_common_properties_str, $a_proper_properties_str) 
		{
            parent::__construct($a_parent_component,$a_parent_part,$a_common_properties_str, $a_proper_properties_str);
          //  echo "count:".count($this->fields_list);
			// steps
            $this->steps_list[t_base_action::step_start] = t_base_step::create_step_from_string('|t_step_ajax_start|'.$this->get_action_name().'_start|'.
              $this->fields_list[t_base_action::step_start].'|'); 
            $this->steps_list[t_base_action::step_criteria] = t_base_step::create_step_from_string('|t_step_ajax_get|'.$this->get_action_name().'_list|'.
              $this->fields_list[t_base_action::step_criteria].'|'); 
			$this->steps_list[t_base_action::step_result] = t_base_step::create_step_from_string('|t_step_ajax_put|'.$this->get_action_name().'_res|'.
              $this->fields_list[t_base_action::step_result].'|');   
            if ($this->fields_list[t_base_action::step_finalize] != '')
            {
                $this->steps_list[t_base_action::step_finalize] = t_base_step::create_step_from_string('|t_step_set_html_tag_property|'.$this->get_action_name().'_finalize|'.
                    $this->fields_list[t_base_action::step_finalize].'|disabled|false|'); 
            } 			  
           /* if ($this->fields_list[3] != '')
            {
                //$this->steps_list[3] = t_base_step::create_step_from_string('|t_step_set_html_tag_property|'.$this->get_action_name().'_finalize|'.
                  //  $this->fields_list[3].'|disabled|false|'); 
            }        */
			
		}
        // D
		public function do_action_from_ajax()
        {
			global $g_strings_utility_namespace;
			global $g_ambient_namespace;
			global $g_url_parameters_namespace;
            $local_invalid_value_list = '';
			$local_result = new t_content_loader_result;
			$local_parameter = parent::do_action_from_ajax();
			//print_r($this->page_fields);
           
			$local_field = $this->steps_list[t_base_action::step_result]->field;
			
			$local_select_location_query = $this->get_action_name()."_query";
			//echo $this->proper_properties_array[self::proper_properties_position_per_SQL];
            $local_action_event = $this->get_first_parent_action_class("t_action_set_event_part");
			//print_r($local_action_event);
			// PARENT COMPONENT
			$local_component = $this->parent_component;
			
            if ($this->is_body_event_action())
			{
				$local_event_type = $local_parameter->get_argument_value(3);
				$local_row_type = $local_parameter->get_argument_value(4);
				echo "PARAMETER: ". $g_ambient_namespace->remove_hide_separator($local_parameter->get_argument_value(5));  
                $local_parameters_array = $g_ambient_namespace->remove_hide_separator(explode(t_url_parameter::separator_level_1,$local_parameter->get_argument_value(5)));
				// GET QUERY
				$local_event_sql = $local_component->get_specific_event_query($local_event_type);
				 echo __METHOD__ . " - local_event_type: $local_event_type <br>";
			}
			else
			{
				//echo "PARAMETER: ". $g_ambient_namespace->remove_hide_separator($local_parameter->get_argument_value(3));  
                $local_parameters_array = $g_ambient_namespace->remove_hide_separator(explode(t_url_parameter::separator_level_1,$local_parameter->get_argument_value(3)));
			}
           // print_r($local_parameters_array);
			if ($local_event_sql == '')
				$local_query_query = trim($this->proper_properties_array[self::proper_properties_position_per_SQL]);
			else	
			    $local_query_query = $local_event_sql;
			//echo "local_query_query: $local_query_query<br>";
			//
								$local_field_to_use = true;
				
			if ($this->is_body_event_action() && (($local_query_query == '') || ($local_row_type == t_field_grid::row_action_name_MUACT)))
            {

				/************ query must be created ***************/
				
				$local_parent_part = $this->parent_part;
                $local_main_table = $local_parent_part->sql_table; 
                $local_query_part_to_update = '';
                $local_query_part_to_insert = '';
                $local_query_part_to_delete = "DELETE FROM " . $local_main_table . " WHERE ";
				$local_where = '';
				$local_key_field_index = 0;
				$local_primary_key_value = null;
               // echo "local_main_table: $local_main_table<br>";
				//echo "local_parent_part class:" . get_class($local_parent_part);
				//echo "local_parent_part: ".$local_parent_part->get_part_name()." - local_parent_part->db_fields: ". isset($local_parent_part->db_fields); 
                foreach ($local_parent_part->db_fields as $local_db_field_index => $local_db_field)
                {
                    $local_to_process = 'true';
					if ($local_row_type == t_field_grid::row_action_name_MUACT)
					{
						$local_db_field_values = json_decode($local_parameters_array[$local_db_field_index]);
						//print_r($local_db_field_values);
						$local_to_process = $local_db_field_values[0];
						
					}
					
					if ($local_to_process == 'true')
					{
						echo "local_db_field->table: $local_db_field->table - local_db_field->orgname: $local_db_field->orgname<br>"; 
						if($local_db_field->numeric != 1)
							$local_value = "':$local_db_field->orgname:'";
						else
							$local_value = ":$local_db_field->orgname:";
						if (($local_db_field->primary_key != 1) && (strtoupper($local_db_field->table) == strtoupper($local_main_table)))
						{
							if ($local_query_part_to_update == '')
							{
								$local_query_part_to_update = "UPDATE " . $local_db_field->table . 
									" SET `$local_db_field->orgname` = $local_value WHERE ";
								$local_query_part_to_insert = "INSERT INTO " . $local_db_field->table . 
									" (`$local_db_field->orgname`) VALUES ($local_value);";
								     
							}
							else 
							{
								$local_query_part_to_update = str_replace(' WHERE', 
									", `$local_db_field->orgname` = $local_value WHERE", $local_query_part_to_update);
								$local_query_part_to_insert = str_replace(array(') VALUES',');'), 
									array(",`$local_db_field->orgname`) VALUES",",$local_value);"), $local_query_part_to_insert);
							}
						} 
						else if ($local_db_field->primary_key == 1)
						{ 
							$local_key_field_index = $local_db_field_index; 
							//$local_main_table = strtoupper($local_db_field->table);
							
							
						}
					}

                }
				
				
				// db key field
				$local_key_db_field = $local_parent_part->db_fields[$local_key_field_index];	
				$local_value = "";
				if ($local_row_type == t_field_grid::row_action_name_MUACT)
				{
					if ($local_parameters_array[$local_key_field_index] == '[]')
						$local_value = "= $local_key_db_field->orgname";
					else
						$local_value = "IN (:$local_key_db_field->orgname:)";
				}
				else if ($local_key_db_field->numeric != 1)
						$local_value = "= ':$local_key_db_field->orgname:'";
                    else
                        $local_value = "= :$local_key_db_field->orgname:";
				if ($local_where == '')
				{
					$local_where = " (`$local_key_db_field->orgname` $local_value) ";
					$local_primary_key_value = $local_value;
				}
				else
				{
					$local_where .= "and (`$local_key_db_field->orgname` $local_value) ";
				}
				
				
				if (! isset($local_primary_key_value))
					exit;
				
				if ($local_event_type == t_base_field::field_event_type_on_insert)
					$local_query_query = $local_query_part_to_insert; 
				else if ($local_event_type == t_base_field::field_event_type_on_delete)
					$local_query_query = $local_query_part_to_delete . $local_where;	
                else
					$local_query_query = $local_query_part_to_update . $local_where;	
				
				//echo "local_query_query: $local_query_query";
                $local_component->new_query(
                    $local_select_location_query,
                    $local_query_query,
                    $g_ambient_namespace->connection);
                //
                $local_query_query = $local_component->get_query(
                    $local_select_location_query);
                $local_query_query->reset_parameters();    

				$local_value_index = 0;
                
                foreach ($local_parent_part->db_fields as $local_db_field_index => $local_db_field)
                {
					$local_to_process = 'true';
					if (($local_row_type == t_field_grid::row_action_name_MUACT) && ($local_key_field_index != $local_db_field_index))
					{
						$local_db_field_values = json_decode($local_parameters_array[$local_db_field_index]);
						$local_to_process = $local_db_field_values[0];
						$local_parameters_array[$local_db_field_index] = $local_db_field_values[1];
					}
					
					if (($local_to_process == 'true') || ($local_key_field_index == $local_db_field_index))
					{
						//echo "local_db_field->table: $local_db_field->table == local_main_table: $local_main_table<br>";
						//echo "local_db_field->type: $local_db_field->type<br>";
						if (((t_query_parameter::get_field_type($local_db_field->type) == 'datetime') || (t_query_parameter::get_field_type($local_db_field->type) == 'date') || (t_query_parameter::get_field_type($local_db_field->type) == 'time')) && 
							(($local_db_field->not_null == 0) || (trim($local_parameters_array[$local_db_field_index]) != '')))
						{
							//echo "PRIMA - local_parameters_array[$local_db_field_index]: $local_parameters_array[$local_db_field_index]<br>";
							if (trim($local_parameters_array[$local_db_field_index]) == '')
							{
								//echo "NULL<br>";
								$local_parameters_array[$local_db_field_index] = 'NULL';
							}
							else
								$local_parameters_array[$local_db_field_index] = 
									$g_strings_utility_namespace->get_mysql_datetime_fromat_from_ambient_datetime_value($local_parameters_array[$local_db_field_index]);
							//echo "DOPO - local_parameters_array[$local_db_field_index]: $local_parameters_array[$local_db_field_index]<br>";	
						}
						//echo "local_db_field->orgname: $local_db_field->orgname - local_parameters_array[local_db_field_index]:$local_parameters_array[$local_db_field_index]<br>";
						if ($local_event_type != t_base_field::field_event_type_on_delete) 
						{
							if (((!isset($local_field)) || ((method_exists($local_field,'is_db_field_to_be_check')) && ($local_field->is_db_field_to_be_check($local_db_field_index)))) && ($local_query_query->is_not_correct_value($local_db_field,$local_parameters_array[$local_db_field_index],$local_db_field_index)))
							{
								//echo "local_db_field->orgname: $local_db_field->orgname - local_parameters_array[local_db_field_index]:$local_parameters_array[$local_db_field_index]<br>";
								if($local_invalid_value_list == '')
								{
									
									$local_invalid_value_list = $this->lang[self::language_position_invalid_fields_values]." `$local_db_field->orgname`";
								}
								else
									$local_invalid_value_list .= ", `$local_db_field->orgname`";
							}
						}
						if ($local_event_type != t_base_field::field_event_type_on_delete) 
						{        
							//echo "$local_db_field->orgname - value:$local_parameters_array[$local_db_field_index] - primary_key: $local_db_field->primary_key<br>"; 
							if (($local_db_field->primary_key != 1) && ($local_key_field_index != $local_db_field_index) &&
							(strtoupper($local_db_field->table) == strtoupper($local_main_table)))
							{
							   // echo "local_db_field->orgname: $local_db_field->orgname - local_parameters_array[local_db_field_index]:$local_parameters_array[$local_db_field_index]<br>";
								if (strtoupper($local_db_field->table) == strtoupper($local_main_table))
								{
									$local_query_query->set_value_parameter(
										$local_parameters_array[$local_db_field_index],$local_value_index);
								}                            
								$local_value_index ++;	
								//echo "index: $local_value_index - value:".$local_parameters_array[$local_value_index];
									
							}
							else if (strtoupper($local_db_field->table) == strtoupper($local_main_table))
							{
								
								$local_primary_key_value = $local_parameters_array[$local_value_index];
								
								
							}	
								
						}
						else
							$local_primary_key_value = $local_parameters_array[$local_value_index];
					}
                }  
				if ($local_row_type == t_field_grid::row_action_name_MUACT)
				{
					$local_search[] = '[';
					$local_search[] = ']';
					$local_search[] = '"';
					$local_replace[] = '';
					$local_replace[] = '';
					$local_replace[] = "'";
					$local_primary_key_value = str_replace($local_search, $local_replace,$local_primary_key_value);
					echo"local_primary_key_value: $local_primary_key_value<br>";
					
				}
				$local_query_query->add_parameter_as_last($local_primary_key_value,true);
				//echo "SQL: ". $local_query_query->retrive_sql_query_with_value_parameter($local_query_query->sql_str)."<br>";
				
				
            }
            else
            {
                /************************* query found *******************/
                $local_where = '';
                $local_component->new_query(
                    $local_select_location_query,
                    $local_query_query,
                    $g_ambient_namespace->connection);
                //
                $local_query_query = $local_component->get_query(
                    $local_select_location_query);
				$local_query_query->reset_parameters();
                //echo "ARGOMENTO ID: ". $local_parameter->get_argument_value(2);   
				if (count($this->page_fields) == 0)
					$this->import_page_fields_from_paret_part();
                //print_r($this->page_fields);
				$local_parameter_index = 0;
				echo "local_query_query->main_table_name: $local_query_query->main_table_name<br>";
                foreach ($this->page_fields as $local_db_field_index=>$local_db_field) 
				{
   		
					//echo "local_db_field->table: $local_db_field->table - local_db_field->orgname: $local_db_field->orgname - local_db_field->type: $local_db_field->type - local_db_field->not_null: $local_db_field->not_null - local_db_field->primary_key: $local_db_field->primary_key - local_db_field->unique_key: $local_db_field->unique_key - local_db_field->auto_increment: $local_db_field->auto_increment - local_parameters_array[local_db_field_index]:$local_parameters_array[$local_db_field_index]<br>";

					if (((t_query_parameter::get_field_type($local_db_field->type) == 'datetime') || (t_query_parameter::get_field_type($local_db_field->type) == 'date') || (t_query_parameter::get_field_type($local_db_field->type) == 'time')) && 
						(($local_db_field->not_null == 0) || (trim($local_parameters_array[$local_db_field_index]) != '')))
					{
						if (trim($local_parameters_array[$local_db_field_index]) == '')
						{
						    //echo "NULL<br>";
							$local_parameters_array[$local_db_field_index] = 'NULL';
						}
						else
							$local_parameters_array[$local_db_field_index] = 
								$g_strings_utility_namespace->get_mysql_datetime_fromat_from_ambient_datetime_value($local_parameters_array[$local_db_field_index]);
					}
					else if ((t_query_parameter::get_field_type($local_db_field->type) == 'int') && ($local_db_field->not_null == 0) && (trim($local_parameters_array[$local_db_field_index]) == ''))
					{
						//echo "NULL";
						$local_parameters_array[$local_db_field_index] = 'NULL';
					}
					
					if ($local_event_type != t_base_field::field_event_type_on_delete) 
					{
						//echo "local_db_field->orgname: $local_db_field->orgname - local_field->special_columns_definition[$local_db_field_index][0]: ".$local_field->special_columns_definition[$local_db_field_index][0]." - local_parameters_array[local_db_field_index]:$local_parameters_array[$local_db_field_index]<br>";
						/****** check for value consistence ******/
						if (($local_db_field->table == $local_query_query->main_table_name) && 
							(((!isset($local_field)) || ((method_exists($local_field,'is_db_field_to_be_check')) && ($local_field->is_db_field_to_be_check($local_db_field_index)))) && ($local_query_query->is_not_correct_value($local_db_field,$local_parameters_array[$local_db_field_index],$local_db_field_index))))
						{
							
							if($local_invalid_value_list == '')
							{
								//echo "INVALIDDDDDDDDDDDDDDDD!!!!!!!!!!!!!!!!!!";
                                
								$local_invalid_value_list = $this->lang[self::language_position_invalid_fields_values]." `$local_db_field->orgname`";
                            }
							else
                                $local_invalid_value_list .= ", `$local_db_field->orgname`";
						}
					}


					if ($local_query_query->main_table_name == '')
					{
						/******** query is a procedure or a function ********/
						
						//echo "local_db_field->table: $local_db_field->table - local_query_query->main_table_name: $local_query_query->main_table_name<br>";
						
							
						if ($local_db_field->primary_key == 1)
						{
							/* the field is a primary key */
							
							if ($local_parameters_array[$local_db_field_index] == '')
							{
							
								/* assign 0 as key value if it is not specified */
								$local_parameters_array[$local_db_field_index] = 0;
							}
						}
						/* substitute parameter with his value */	
						$local_query_query->set_value_parameter(
							$local_parameters_array[$local_db_field_index],$local_parameter_index);
						//echo "index: $local_db_field_index - value:".$local_parameters_array[$local_db_field_index];		
						$local_parameter_index++;						
							
						
					}
					else if ($local_db_field->primary_key != 1)
					{
						/*********** it is a query and the field is not a primary_key ********/
						
						//echo "local_db_field->table: $local_db_field->table - local_query_query->main_table_name: $local_query_query->main_table_name<br>";
						if ($local_db_field->table == $local_query_query->main_table_name)
						{
							/* the field belong to the main table of the query */
							
							
							/* substitute parameter with his value */	
							$local_query_query->set_value_parameter(
								$local_parameters_array[$local_db_field_index],$local_parameter_index);
							//echo "index: $local_db_field_index - value:".$local_parameters_array[$local_db_field_index];		
							$local_parameter_index++;						
						}	
						
					}
					else
					{ 
						/******** it is a query and it is a primary key field ********/
						
						//$local_main_table = strtoupper($local_db_field->table);
						
						if ($local_where == '')
						{
							$local_where = " (`$local_db_field->orgname` = $local_parameters_array[$local_db_field_index]) ";
							$local_primary_key_value = $local_value;
						}
						else
						{
							$local_where .= "and (`$local_db_field->orgname` = $local_parameters_array[$local_db_field_index]) ";
						}
					}
						
					
					
                } 
				if (($local_where != '') && ($local_event_type != t_base_field::field_event_type_on_insert) )
				{
					$local_query_query->sql_str = $local_query_query->sql_str . " WHERE " . $local_where;
				}
				$local_fixed_fileds_names = $this->proper_properties_array[self::proper_properties_position_per_fixed_fields_names];
				$local_fixed_fileds_values = $this->proper_properties_array[self::proper_properties_position_per_fixed_fields_values];
				//print_r($local_fixed_fileds_names);
				foreach ($local_fixed_fileds_names as $local_fixed_name_index=>$local_fixed_name) 
				{
					//echo "local_fixed_name: $local_fixed_name ";
					$local_db_field_index = $local_query_query->get_parameter_index_by_name($local_fixed_name);
					if ($local_db_field_index >= -1)
					{
						//echo "local_db_field_index: $local_db_field_index - value:".$local_fixed_fileds_values[$local_fixed_name_index];
						$local_query_query->set_value_parameter(
							$local_fixed_fileds_values[$local_fixed_name_index],$local_db_field_index);
						
					}			
				}
				//echo "SQL: ". $local_query_query->retrive_sql_query_with_value_parameter($local_query_query->sql_str)."<br>";
			}
			if ($local_invalid_value_list != '')
			{
				$local_result->error_msg  = $local_invalid_value_list;
			}	
			else
			{
				//$local_query_query->start_transaction();
				try
				{
					$local_result->succeeded = $local_query_query->execute_query();
					//echo "local_result->succeeded: $local_result->succeeded<br>";
					if (! $local_result->succeeded)
						$local_result->error_msg = $local_query_query->get_last_error();
					else
					{
						// PUTS QUERY RESULTS INTO URL PARAMETER
                        //print_r($local_query_query->sql_values);
                        //echo "local_query_query->get_field_value(0): ".$local_query_query->get_field_value(0)."<br>";
						$local_query_query->execute_function_from_query_result($local_query_query,"put_query_result_into_url_parameter",$local_parameter);
						$local_query_query->free_sql_result();
						$this->execute_child_ations($local_result,$local_query_query->connection);
						
					}
				}
				catch(Exception $e)
				{
					$local_result->succeeded = false;
					$local_result->error_msg .= $e->getMessage();	
					$this->log->add_log_error(__METHOD__ . ": unexpected error: ".$e->getMessage(),NULL,true);//mysql_error());
				}
				//$local_query_query->stop_transaction($local_result->succeeded);
				
			}
			//echo "local_result->succeeded: ".$local_result->succeeded."<br>";
			
			if ($local_action_event != null)
			{
				//echo "local_action_event OK\n";
				$local_field->get_result_action_script($local_action_event->get_event_type(),
                    $local_event_type,$local_parameter->get_argument_value(4),$local_result);	
			}		
			if ($this->enable_language)
			{
				if ($local_result->succeeded)
					$local_result->error_msg = $this->lang[self::language_position_ok_message];
				else	
					$local_result->error_msg = $this->lang[self::language_position_error_message];
			}
			echo $local_result->get_json_string();

        }
        // G

		public function get_language_position_last()
        {
            return self::language_position_last;
        }

        
    }
?>    